package com.hejielife.volatil;

/**
 * 2019年8月1日 下午3:24:35
 * 
 * @author hejielife
 * @despribe synchronized异常处理方法
 */
public class SyncException {

	private int i = 0;

	public synchronized void operation() {
		while (true) {
			try {
				i++;
				Thread.sleep(100);
				System.out.println(Thread.currentThread().getName() + " , i = " + i);
				if (i == 20) {
					 Integer.parseInt("a");
					//抛一个RuntimeException
					//throw new RuntimeException();
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) {

		final SyncException se = new SyncException();
		Thread t1 = new Thread(new Runnable() {
			public void run() {
				se.operation();
			}
		}, "t1");
		t1.start();
	}

}
